#define  _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>


typedef int ElmeType;
typedef struct Node
{
	ElmeType data;
	struct Node* next;
}Node,*LinkList;

LinkList InitLst(ElmeType x)
{
	Node* newNode = (Node*)malloc(sizeof(Node));
	newNode->data = x;
	newNode->next = NULL;
	return newNode;
}



int getElme(LinkList L, int i, ElmeType& e)
{
	Node* p = L->next;
	int j = 0;
	while (p && j < i)
	{
		j++;
		p = p->next;
	}
	if (p == NULL)
		return -1;
	if (j > i)
		return -2;
	e = p->data;
	return 0;
}

void Insert(LinkList& L, int i, ElmeType e)
{
	Node* p = L -> next;
	int j = 0;
	while (p && j < i - 1)
	{
		j++;
		p = p->next;
	}
	if (!p || j > i - 1)
		return;
	Node* newNode = (Node*)malloc(sizeof(Node));
	newNode->data = e;
	newNode->next = p->next;
	p->next = newNode;
}


void DelLsit(LinkList& L, int i, ElmeType& e)
{
	Node* cur = L->next;
	int j = 0;
	while (cur->next && j < i - 1)
	{
		j++;
		cur = cur->next;
	}
	if (cur->next == NULL || j > i - 1)
		return;
	Node* next = cur->next;
	cur->next = next->next;
	e = next->data;
	free(next);
}
